/**
 * This is a listener class for insurance
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;


/**
 * @author Master
 * @version $Revision: 1.0 $
 */
public class InsuranceListener implements ActionListener{
	/**
	 * Method toString.
	
	 * @return String */
	@Override
	public String toString() {
		return "InsuranceListener []";
	}

	/**
	 * Field INSURANCE.
	 */
	public static final int INSURANCE = 10000;

	/**
	 * Method actionPerformed.
	 * @param arg0 ActionEvent
	
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
	@Override 
	public void actionPerformed(ActionEvent arg0) {
		if (!PlayerInfo.canGetInsurance()){
			if(PlayerInfo.getMoney() > INSURANCE){
			JOptionPane.showMessageDialog(
				ConfigurationScreen.MyFrame, 
				"You are going to spend 10000 bugs to get an insurance");
			PlayerInfo.setInsurance(true);
			PlayerInfo.setMoney(PlayerInfo.getMoney() - INSURANCE);
			MarketPlaceScreen.Money.setText(Integer.toString(PlayerInfo.getMoney()));
			}
			else {
				JOptionPane.showMessageDialog(
					ConfigurationScreen.MyFrame,
					"You don't have enough money to buy insurance");
			}
		}
		else {
			JOptionPane.showMessageDialog(
				ConfigurationScreen.MyFrame, 
				"You have bought an insurance. You cannot buy another");
		}
	}
	
	
}
